Conversation
sumitmsft
reviewed
Aug 25, 2025
sumitmsft
reviewed
Aug 25, 2025
sumitmsft
reviewed
Aug 25, 2025
bewithgaurav
requested changes
Aug 25, 2025
sumitmsft
reviewed
Aug 25, 2025
sumitmsft
reviewed
Aug 25, 2025
sumitmsft
reviewed
Aug 25, 2025
sumitmsft
requested changes
Aug 25, 2025
Contributor
sumitmsft
left a comment
There was a problem hiding this comment.
Left a few comments...
### Work Item / Issue Reference <!-- IMPORTANT: Please follow the PR template guidelines below. For mssql-python maintainers: Insert your ADO Work Item ID below (e.g. AB#37452) For external contributors: Insert Github Issue number below (e.g. #149) Only one reference is required - either GitHub issue OR ADO Work Item. --> <!-- mssql-python maintainers: ADO Work Item --> > [AB#34934](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34934) ------------------------------------------------------------------- ### Summary This pull request adds support for retrieving ODBC data type information via a new `getTypeInfo` method on the `cursor` object, exposing the underlying `SQLGetTypeInfo` API. It includes the necessary C++/Python bindings, error handling, and comprehensive test coverage to ensure correct behavior for different data types and usage scenarios. ### Feature: Data type information retrieval * Added a new `getTypeInfo` method to the `cursor` class in `mssql_python/cursor.py`, allowing users to retrieve metadata about supported SQL data types via the ODBC `SQLGetTypeInfo` API. The method supports querying all types or a specific type and returns results as a list of `Row` objects with a well-defined column map. ### Bindings and driver integration * Introduced a new function pointer type for `SQLGetTypeInfo` (`SQLGetTypeInfoFunc`) and integrated it into the driver loading and verification process in `mssql_python/pybind/ddbc_bindings.h` and `mssql_python/pybind/ddbc_bindings.cpp`. This ensures the function pointer is loaded and checked along with other ODBC APIs. * Added a wrapper function and Python binding for `SQLGetTypeInfo`, exposing it as `DDBCSQLGetTypeInfo` in the Python module. ### Testing * Added a comprehensive suite of tests in `tests/test_004_cursor.py` to validate the new `getTypeInfo` method. Tests cover retrieving all types, specific types, result structure, numeric and datetime types, binary types, multiple successive calls, and repeated identical queries for consistency and efficiency. --------- Co-authored-by: Jahnvi Thakkar <[email protected]>
…osoft/mssql-python into jahnvi/cursor_setinputsizes
sumitmsft
approved these changes
Sep 15, 2025
sumitmsft
previously approved these changes
Sep 16, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive support for advanced SQL metadata and catalog functions to the MSSQL Python bindings, implementing setinputsizes functionality and various ODBC catalog APIs for database introspection.
- Addition of
setinputsizesmethod for explicit SQL parameter type specification - Implementation of ODBC catalog APIs (SQLGetTypeInfo, SQLProcedures, SQLForeignKeys, etc.)
- Addition of SQL type constants at module level and enhanced constants management
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_003_connection.py | Adds comprehensive test suite for connection methods, output converters, and timeout functionality with some duplicate code removal |
| tests/test_001_globals.py | Adds tests for decimal separator functionality with some duplicate test definitions |
| mssql_python/pybind/ddbc_bindings.h | Defines new ODBC catalog function type definitions and external declarations |
| mssql_python/pybind/ddbc_bindings.cpp | Implements wrapper functions for catalog APIs and adds Python bindings |
| mssql_python/cursor.py | Implements setinputsizes method and adds catalog API methods (getTypeInfo, procedures, etc.) |
| mssql_python/constants.py | Adds new constants for catalog APIs and SQLTypes utility class |
| mssql_python/init.py | Exports SQL type constants at module level for easier access |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
sumitmsft
approved these changes
Sep 18, 2025
bewithgaurav
approved these changes
Sep 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work Item / Issue Reference
Summary
This pull request adds comprehensive support for advanced SQL metadata and catalog functions to the MSSQL Python bindings, making it easier to interact with database schema information and supported data types from Python. The changes include new wrapper functions and Python bindings for several ODBC catalog APIs, the addition of SQL type constants, and enhancements to the constants module for easier type validation and categorization.
SQL Catalog & Metadata API Support
SQLGetTypeInfo,SQLProcedures,SQLForeignKeys,SQLPrimaryKeys,SQLSpecialColumns,SQLStatistics, andSQLColumnsinddbc_bindings.cpp. These allow Python code to directly query metadata about tables, columns, keys, procedures, and supported types.Constants and Type Handling
SQL_CHAR,SQL_INTEGER, etc.) at the module level in__init__.pyfor easier use in Python code.ConstantsDDBCfor catalog API parameters such asSQL_SCOPE_CURROW,SQL_BEST_ROWID,SQL_ROWVER, and others.SQLTypesclass inconstants.py, providing methods to retrieve sets of valid SQL types and categorize them (e.g., string types, numeric types), which can help with input validation and type checking in Python.These changes significantly improve the ability of Python applications to introspect and work with database schema and type information, making your code more robust and flexible when dealing with SQL Server databases.